<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>白名单 列表</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="FXBR">
                    <div class="fieldBox">
                        <div class="label">用户ID</div>
                        <div class="field">
                            <input name="usrId" id="usrId" type="text" class="ui-textbox" value="" ligerui="width: 160">
                        </div>
                        <div class="label">客户ID</div>
                        <div class="field">
                            <input name="cstId" id="cstId" type="text" class="ui-textbox" value="" ligerui="width: 160">
                        </div>
                        <div class="label">客户姓名</div>
                        <div class="field">
                            <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="" ligerui="width: 160">
                        </div>
                        <div class="label">客户手机号</div>
                        <div class="field">
                            <input name="cstMp" id="cstMp" type="text" class="ui-textbox" value="" ligerui="width: 160">
                        </div>
                    </div>
                </div>
                <div class="clearFix"></div>
                <div class="btnsBox formBtns notRight">
                    <span id="searchBtn" onclick="searchBtn();" class="sq-button-round">查询</span>
                    <span id="clearBtn" onclick="clearBtn();" class="sq-button-round">清空</span>
                    <span id="addBtn" onclick="addBtn();" class="sq-button-round">新增</span>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="mcrWhiteInspectGrid" class="sq-grid"></div>

<script type="text/javascript">
    let grid = null;
    $(function () {
        initForm();
        initGrid();
    });

    //初始化表单
    function initForm() {
        $("#searchBar").ligerForm();
    }

    //查询按钮事件
    function searchBtn() {
        const form = new liger.get("searchBar");
        const data = form.getData();
        for (const name in data) {
            grid.setParm(name, data[name]);
        }
        grid.reload();
    }

    //查询参数
    function getSearchParams() {
        const form = new liger.get("searchBar");
        return form.getData();
    }

    //初始化列表
    function initGrid() {
        $("#mcrWhiteInspectGrid").ligerGrid({
            url: '<%=path%>/mcr/whiteInspect/initList.do',
            method: 'post',
            isSingleCheck: false,
            parms: getSearchParams(),
            columns: [
                {display: '用户ID', name: 'usrId', width: 120, align: 'left', enabledSort: true},
                {display: '客户ID', name: 'cstId', width: 120, enabledSort: true},
                {display: '客户姓名', name: 'cstNm', width: 150, enabledSort: true},
                {display: '客户手机号', name: 'cstMp', width: 120, enabledSort: true},
                {display: '征信等级', name: 'creditLvl', width: 120, enabledSort: true},
                {display: '放款次数', name: 'loanCount', width: 150, enabledSort: true},
                {display: '单笔限额', name: 'singleAmt', width: 150, enabledSort: true},
                {display: '单日限额', name: 'dayAmt', width: 150, enabledSort: true},
                {display: '本月最高限额', name: 'mothAmt', width: 150, enabledSort: true},
                {display: '业务类型', name: 'busType', width: 150, enabledSort: true},
                {display: '用户类型', name: 'busTypeDtl', width: 150, enabledSort: true},
                {display: '有效期开始时间', name: 'startTm', width: 150, enabledSort: true},
                {display: '有效期截止时间', name: 'endTm', width: 150, enabledSort: true},
                {
                    display: '状态', name: 'isValid', width: 150, enabledSort: true,
                    render: function (rowdata, index, value) {
                        if (rowdata.isValid === 1) {
                            return "有效";
                        } else {
                            return "无效";
                        }
                    }
                },
                getGridOperColumnContent()
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true
        });
        grid = liger.get("mcrWhiteInspectGrid");
    }

    //Grid操作列
    function getGridOperColumnContent() {
        return {
            display: '操作',
            isSort: false,
            width: 280,
            render: function (rowdata, rowindex, value) {
                let a = '<a class="sq-button-hasicon" href="javascript:deleteRow(';
                a += "'" + rowdata.id + "'";
                a += ",'mid_man_grid_id'"
                a += ")\"><i class=\"sqBtnIco_7\"></i>删除</a>"

                let b = '<a class="sq-button-hasicon" href="javascript:addBtn(';
                b += "'" + rowdata.id + "'";
                b += ",'mid_man_grid_id'"
                b += ")\"><i class=\"sqBtnIco_4\"></i>修改</a>"

                let z = '<a class="sq-button-hasicon" href="javascript:modifyUnValid(';
                z += "'" + rowdata.id + "'";
                z += ",'mid_man_grid_id'"
                z += ")\"><i class=\"sqBtnIco_7\"></i>置为无效</a>"

                return a + b + z;
            }
        };
    }

    //删除数据
    function deleteRow(_id) {
        $.ligerDialog.confirm('确定删除吗?', function (flag) {
            if (flag === false) return;
            const url = '<%=path%>/mcr/whiteInspect/removeById.do';
            AjaxUtils.ajaxPost(url, {id: _id}, ajaxCallback);
        });
    }

    //作废数据
    function modifyUnValid(_id) {
        $.ligerDialog.confirm('确定要置为无效?', function (flag) {
            if (flag === false) return;
            const url = '<%=path%>/mcr/whiteInspect/unValidById.do';
            AjaxUtils.ajaxPost(url, {id: _id}, ajaxCallback);
        });
    }

    // 请求回调
    function ajaxCallback(msg) {
        if (msg.success === 1) {
            UIUtils.alertSuccess(msg.info);
            grid.reload();
        } else {
            UIUtils.alertError(msg.info);
        }
    }

    //新增
    function addBtn(_id) {
        let titleName = "新增";
        if(StringUtils.isNotEmpty(_id)){
            titleName = "修改";
        }
        $.ligerDialog.SQopen({
            width: 800,
            height: 200,
            title: titleName,
            url: '<%=path%>/mcr/whiteInspect/toAdd.do',
            buttons: [{
                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
                onclick: function (item, Dialog) {
                    if (Dialog.onOk) {
                        Dialog.onOk();
                    }
                }
            }, {
                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                onclick: function (item, Dialog) {
                    if (Dialog.onCancel) {
                        Dialog.onCancel()
                    }
                }
            }
            ]
        });
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        let dateStr = "";
        if (null != value) {
            const date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    //清空按钮事件
    function clearBtn() {
        $("#resetBtn").click();  //重置 input-text
        const form = new liger.get("searchBar");
        form.setData({  //重置select等特殊表单
            "usrId": "",
            "cstId": "",
            "cstNm": "",
            "cstMp": ""
        });
    }

</script>

</body>
</html>